package com.tiantong.aibilian;

import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.os.Handler;
import android.os.Message;


import com.tiantong.aibilian.config.API;
import com.tiantong.aibilian.model.ServerBean;
import com.tiantong.aibilian.socket.MyServer;
import com.tiantong.aibilian.socket.ServerInterface;

import org.json.JSONArray;
import org.json.JSONObject;

import java.net.URISyntaxException;

import io.socket.client.IO;
import io.socket.client.Socket;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;


public class Myappliction  extends Application {

    protected MyServer server;
    protected io.socket.client.Socket mSocket;
    private Context mcontent;
    private SharedPreferences sp;
    public io.socket.client.Socket getSocket() {
        return mSocket;
    }
    @Override
    public void onCreate()
    {
        super.onCreate();
        mcontent= this;
        sp = getSharedPreferences("cache", Context.MODE_PRIVATE);

      //  initSocket();
    }
    public MyServer getserver(){

        return server;
    }
    private void initSocket() {
        try {
            if (API.Socket_URL != "") {
                IO.Options option = new IO.Options();
                option.forceNew = true;
                option.reconnection = true;
                option.reconnectionDelay = 1000*60;
                mSocket = IO.socket(API.Socket_URL, option);
            }
            String code = sp.getString("code", "ccc");
            server = new MyServer(new ChatListenUIRefresh(), mcontent);
            server.init(code);
//            server.heartbeat(mHandler);

        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
    }
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 1:
                    try {

                    }catch (Exception e){

                    }

                    break;

            }
        }
    };

    //socket客户端事件监听处理
    private class ChatListenUIRefresh implements ServerInterface {


        @Override
        public void onMessageListen(ServerBean chatBean) {


        }

        @Override
        public void onConnect(boolean res) {
            if (res) {

            }
        }

        @Override
        public void onError() {

        }

        @Override
        public void onDisconnect() {

        }

    }



}
